﻿using System;
using System.IO;
using SellAndBuy.Domain.Core;

namespace SellAndBuy.Domain.Entities
{
    /// <summary>
    /// Ad Picture Value Object
    /// </summary>
    public class PictureInfo : ValueObjectBase<PictureInfo>
    {

        /// <summary>
        /// Private Default Constructor
        /// </summary>
        private PictureInfo()
        {}

        /// <summary>
        /// Internal constructor of value object
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <param name="title">Name</param>
        /// <param name="picture">Picture content</param>
        /// <param name="isMain">Is main picture?</param>
        /// <exception cref="ArgumentException">Argument exception of file name</exception>
        /// <exception cref="ArgumentNullException"><paramref name="picture" /> is <c>null</c>.</exception>
        internal PictureInfo(string fileName, string title, byte[] picture, bool isMain)
        {
            // Validate file name
            if (String.IsNullOrWhiteSpace(fileName) || String.IsNullOrWhiteSpace(Path.GetExtension(fileName)))
                    throw new ArgumentException("File name is not valid", "fileName");

            // Validate picture
            if(picture == null)
                throw new ArgumentNullException("picture");

            FileName = fileName;
            Title = title;
            Picture = picture;
            IsMain = isMain;
        }



        /// <summary>
        /// Picture file name
        /// </summary>
        public string FileName { get; private set;}

        /// <summary>
        /// Title of the picture
        /// </summary>
        public string Title { get; private set; }

        /// <summary>
        /// Is main picture?
        /// </summary>
        public bool IsMain { get; internal set; }

        /// <summary>
        /// Picture content
        /// </summary>
        public byte[] Picture { get; private set; }

    }
}